package com.blinddate.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blinddate.pojo.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

@Mapper
public interface OrdersMapper extends BaseMapper<Orders> {

    @Select("SELECT COUNT(*) " +
            "FROM orders WHERE DATE_SUB(CURDATE(), " +
            "INTERVAL #{day} DAY) <= DATE(checkout_time) AND shop_id = #{shopId} " +
            "AND STATUS=1 AND goods_id = #{goodsId};")
    public Long getCountOrders(@Param("day") Integer day,@Param("shopId") Long shopId,@Param("goodsId") Long goodsId);

    @Select("SELECT COUNT(*) " +
            "FROM orders WHERE DATE_SUB(CURDATE(), " +
            "INTERVAL #{day} DAY) <= DATE(checkout_time)" +
            "AND STATUS=1 AND goods_id = #{goodsId};")
    public Long getAllCountOrders(@Param("day") Integer day,@Param("goodsId") Long goodsId);

    @Select("SELECT TO_DAYS(NOW())-TO_DAYS(MIN(checkout_time)) FROM orders WHERE IF(#{shop_id}=0,1=1,shop_id = #{shop_id})")
    public Integer getMOrTime(@Param("shop_id") Long shopId);

}
